import { StyleSheet, Text, View } from 'react-native'
import React, { useState } from 'react'
import { TextArea, Button } from 'native-base'
import UploadFile from '../components/Upload/UploadFile';
import axios from '../axios';

const Publish = ({ navigation }) => {
  const [content, setContent] = useState('')
  const [pictures, setPictures] = useState([])
  const submit = () => {
    axios.post('/news', {
      pictures: pictures,
      content: content
    }).then((res) => {
      navigation.goBack()
    })
  }
  const uploadSucess = (data) => {
    console.log('成功', data)
    setPictures([...pictures, data])
  }
  return (
    <View>
      <TextArea shadow={2} h={120} placeholder="请输入内容" w="100%" _light={{
        placeholderTextColor: 'trueGray.700'
      }} _dark={{
        bg: 'coolGray.800'
      }} _hover={{
        bg: 'coolGray.200'
      }}
        onChangeText={(val) => setContent(val)}
      />
      <UploadFile style={styles.upload} onSuccess={uploadSucess} />
      <Button onPress={submit}>发表</Button>
    </View>
  )
}

export default Publish

const styles = StyleSheet.create({
  upload: {
    // marginHorizontal: 10,
    marginVertical: 10
  }
})